<?php

class NoticeBoardPresenter extends BasePresenter
{

	/**
	 * @persistent
	 */
	public $displayedWeeks = 1;
	/**
	 * @persistent
	 */
	public $monthOffset = 0;
	

	public function renderDefault()
	{
		$calendar = $this->context->models->calendar;
		for ($i = 0; $i < $this->displayedWeeks; $i++)
		{
			$weeks[] = $calendar->getUserCalendar($this->getUser()->getId(), 'week', $i);
		}

		$this->template->calendar = $weeks;

		$tasks = $this->context->models->tasks;

		$this->template->lastComments = $tasks->getLastComments($this->getUser()->getId());
		
		$myProjects = $this->context->models->projects->getUserProjects($this->user->id);
		$this->template->myProjects = $myProjects;
	}

	public function handleAddWeek()
	{
		if ($this->displayedWeeks < 5)
			$this->displayedWeeks++;
		else
			$this->payload->message = "Nelze zobrazit více týdnů";
		if (!$this->isAjax())
		{
			$this->redirect('this');
		} else
		{
			$this->invalidateControl("calendar");
		}
	}

	protected function createComponentTasks()
	{
		$component = new \Tasker\Components\TaskControl();
		return $component;
	}

	public function renderMyCalendar()
	{
		$calendarModel = $this->context->models->calendar;
		$this->template->month = $calendarModel->getUserCalendar($this->getUser()->getId(), 'month', $this->monthOffset);
	}
	
	public function handleMinusMonth()
	{
		
		$this->monthOffset--;
		
		if (!$this->isAjax())
		{
			$this->redirect('this');
		} else
		{
			$this->invalidateControl("calendar");
		}
	}
	
	public function handlePlusMonth()
	{
		
		$this->monthOffset++;
		
		if (!$this->isAjax())
		{
			$this->redirect('this');
		} else
		{
			$this->invalidateControl("calendar");
		}
	}

}
